package com.xjtu.platform.user.consultor.visitRecord.imply;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.user.consultor.visitRecord.FinishVisitDto;
import com.xjtu.platform.user.consultor.visitRecord.InfoDto;
import com.xjtu.platform.user.consultor.visitRecord.VisitRecordDto;
import com.xjtu.platform.user.consultor.visitRecord.VisitRecordService;
import com.xjtu.platform.user.consultor.visitRecord.dao.VisitRecordDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class VisitRecordServiceImpl implements VisitRecordService {

    @Resource
    private VisitRecordDao visitRecordDao;

    @Override
    public Map<String, Object> getInfo(VisitRecordDto visitRecordDto) {
        System.out.println(visitRecordDto.getUser_id());
        return Utils.getPage(visitRecordDto,()->visitRecordDao.getInfo(visitRecordDto));
    }

    @Override
    public boolean insertResult(FinishVisitDto finishVisitDto) {
        try {
            visitRecordDao.insertResult(finishVisitDto);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public List<FinishVisitDto> getVisitInfo(InfoDto infoDto) {
        return visitRecordDao.getVisitInfo(infoDto);
    }

    @Override
    public void sendMail(FinishVisitDto finishVisitDto) {
        String email = visitRecordDao.getStudentEmail(finishVisitDto);
        String type;
        if(finishVisitDto.getType().equals("needConsult")){
            type="安排咨询";
        }else if(finishVisitDto.getType().equals("needDoctor")){
            type="转接送诊";
        }else{
            type="无需咨询";
        }
        String content = "学生您好，您的初访结果已公布，结果为: "+type+" 详情请登录易心理查看";
        try {
            Utils.sendMail(email,content);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
